$(function(){
	var iPlaneID = $("#iPlaneID").val();  
	var url = "backplaneplanjson?iPlaneID=" + iPlaneID;
		/*初始化表格*/
		$('#planePlan').datagrid({
    		url:url,
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 	{field:'planID',hidden:'true'},
				{field:'standard',title:'标准',align:'center',width:'10%'},			
				{field:'planeName',title:'航班名称',align:'center',width:'10%'},
				{field:'zoneOutName',title:'出发地',align:'center',width:'10%'},
				{field:'airportOutName',title:'出发机场',align:'center',width:'10%'},
				{field:'zoneInName',title:'到达地',align:'center',width:'10%'},
				{field:'airportInName',title:'到达机场',align:'center',width:'10%'},
				{field:'startDate',title:'出发时刻',align:'center',width:'19%',formatter:function(value) {
		            var date = new Date(value);
		            var year = date.getFullYear().toString();
		            var month = (date.getMonth() + 1);
		            var day = date.getDate().toString();
		 			var hours = date.getHours().toString();
					var minutes = date.getMinutes().toString();
					var seconds = date.getSeconds().toString();
		            if (month < 10) {
		                month = "0" + month;
		            }
		            if (day < 10) {
		                day = "0" + day;
		            }
					if (hours < 10) {
		                hours = "0" + hours;
		            }
					if (minutes < 10) {
		                minutes = "0" + minutes;
		            }
					if (seconds < 10) {
		                seconds = "0" + seconds;
		            }
		            return year + "-" + month + "-" + day+ " "+hours+":"+minutes+":"+seconds;
		        }},
				{field:'endDate',title:'到达时刻',align:'center',width:'19%',formatter:function(value) {
		            var date = new Date(value);
		            var year = date.getFullYear().toString();
		            var month = (date.getMonth() + 1);
		            var day = date.getDate().toString();
		 			var hours = date.getHours().toString();
		 			var minutes = date.getMinutes().toString();
					var seconds = date.getSeconds().toString();
		            if (month < 10) {
		                month = "0" + month;
		            }
		            if (day < 10) {
		                day = "0" + day;
		            }
					if (hours < 10) {
		                hours = "0" + hours;
		            }
					if (minutes < 10) {
		                minutes = "0" + minutes;
		            }
					if (seconds < 10) {
		                seconds = "0" + seconds;
		            }
		            return year + "-" + month + "-" + day+ " "+hours+":"+minutes+":"+seconds;
		        }}
    		]]
		});
			
});

/*搜索*/
function searchPlanePlan(){
	
		var planeOutDate = $("#planeOutDate").val();
	var planeOutZone = $("#homecity_name1").val(); 
		var planeInZone = $("#getcity_name1").val(); 
		var iPlaneID = $("#iPlaneID").val(); 
		$("#planePlan").datagrid("load",{
			planeOutDate:planeOutDate,
			planeOutZone:planeOutZone,
			planeInZone:planeInZone,
			iPlaneID:iPlaneID
		})
	}
	
/*清空*/
function clearPlanePlan(){
        $("#planeOutDate").val('');
		$("#homecity_name1").val('');
	$("#getcity_name1").val('');
     }


// 修改航班信息
function updatePlanePlan() {
	
	
		var rows = $('#planePlan').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
		
		$.messager.confirm('Confirm', '确定要修改吗?', function(r){
	if (r){
		var iPlanID = rows[0].planID; 
		 	location.href="/mmy/backtoupdateplaneplan?iPlanID="+iPlanID;
	}
});
	
		 }
}



/*进入航班时刻页面*/
function toPlanePlan(){
	var rows = $('#planeBase').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
				var iPlaneID = rows[0].planeID;  
				location.href="/mmy/backtoplaneplanindex?iPlaneID="+iPlaneID;
			}
}
/*选择出发机场*/
function appearAirPort(iZoneID){
	//查询该区域的机场信息
			 $.ajax({
        				url:"/mmy/searchairportID?iZoneID="+iZoneID,
        				type:"post",
        				data:"",
        				dataType:"json",
        				success:function (data) {
var lstAir=data.lstAir;
            //回显选中
    	var select=$("#planAirportOut");
$("#planAirportOut").html("");
var option0=$("<option value=''>--请选择--</option>");
  select.append(option0);
    	for(var i=0;i < lstAir.length;i++){
        var node=lstAir[i];
 
        var option=$("<option value='"+node.airportID+"'>"+node.airportName+"</option>");
       
        select.append(option);
    }
					
        			},
       					 error:function () {
	}
    })
}
/*选择到达机场*/
function appearInAirPort(iZoneID){
	//查询该区域的机场信息
			 $.ajax({
        				url:"/mmy/searchairportID?iZoneID="+iZoneID,
        				type:"post",
        				data:"",
        				dataType:"json",
        				success:function (data) {
var lstAir=data.lstAir;
            //回显选中
    	var select=$("#planAirportIn");
$("#planAirportIn").html("");
  var option0=$("<option value=''>--请选择--</option>");
 select.append(option0);
    	for(var i=0;i < lstAir.length;i++){
        var node=lstAir[i];

        var option=$("<option value='"+node.airportID+"'>"+node.airportName+"</option>");
       
        select.append(option);
    }
					
        			},
       					 error:function () {
	}
    })
}
//后台	飞机时刻表新建与修改时正则验证 2021.03.17
function planPlaneSubmit(planPlaneForm){
	var floor=planPlaneForm.Floor.value;
	var peer=planPlaneForm.Peer.value;
	var price=planPlaneForm.Price.value;
	var number=planPlaneForm.Number.value;
	
if(floor<=0){ 
  $.messager.alert('错误','底价必须大于零','error');
	planPlaneForm.Floor.focus();
	return false;	
    } 
if(peer<=0){ 
  $.messager.alert('错误','同业价必须大于零','error');
	planPlaneForm.Peer.focus();
	return false;	
    } 
if(price<=0){ 
  $.messager.alert('错误','对外报价必须大于零','error');
	planPlaneForm.Price.focus();
	return false;	
    }
if(number<=0){ 
  $.messager.alert('错误','数量必须大于零','error');
	planPlaneForm.Number.focus();
	return false;	
    }
if(parseInt(floor)>=parseInt(peer)) {
	 $.messager.alert('错误','同业价必须大于底价','error');
	planPlaneForm.Peer.focus();
	return false;	
    
}
if(parseInt(peer)>=parseInt(price)) {
	 $.messager.alert('错误','对外报价必须大于同业价','error');
	planPlaneForm.Price.focus();
	return false;	
    }
}
